home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / BookFile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  8.6 KB  |  288 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*******************************************************************************
  19.     BookFile.c
  20.  
  21. *******************************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. #include <Xm/Xm.h>
  26. #include <Xm/DialogS.h>
  27. #include <Xm/MenuShell.h>
  28. #include "UxXt.h"
  29.  
  30. #include <Xm/FileSB.h>
  31.  
  32. /*******************************************************************************
  33.     Includes, Defines, and Global variables from the Declarations Editor:
  34. *******************************************************************************/
  35.  
  36. #include "exinterfmotif.h"
  37. #include <string.h>
  38. #include "exglobals.h"
  39. /*
  40. #include "exinterf.h"
  41. */
  42.  
  43. /*******************************************************************************
  44.     The definition of the context structure:
  45.     If you create multiple instances of your interface, the context
  46.     structure ensures that your callbacks use the variables for the
  47.     correct instance.
  48.  
  49.     For each Widget in the interface, each argument to the Interface
  50.     function, and each variable in the Instance Specific section of the
  51.     Declarations Editor, there is an entry in the context structure.
  52.     and a #define.  The #define makes the variable name refer to the
  53.     corresponding entry in the context structure.
  54. *******************************************************************************/
  55.  
  56. typedef    struct
  57. {
  58.     int    mumble;
  59. } _UxCBookFile;
  60.  
  61.  
  62. static _UxCBookFile    *UxBookFileContext;
  63.  
  64. Widget    BookFile;
  65.  
  66. /*******************************************************************************
  67.     Forward declarations of functions that are defined later in this file.
  68. *******************************************************************************/
  69.  
  70. Widget    create_BookFile();
  71.  
  72. /*******************************************************************************
  73.     The following are callback functions.
  74. *******************************************************************************/
  75.  
  76. static void    okCallback_BookFile( UxWidget, UxClientData, UxCallbackArg )
  77.     Widget        UxWidget;
  78.     XtPointer    UxClientData, UxCallbackArg;
  79. {
  80.     _UxCBookFile            *UxSaveCtx, *UxContext;
  81.  
  82.     UxSaveCtx = UxBookFileContext;
  83.     UxBookFileContext = UxContext =
  84.             (_UxCBookFile *) UxGetContext( UxWidget );
  85.     {
  86.     XmFileSelectionBoxCallbackStruct *cbs;
  87.     cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
  88.     FileName = extract_first_xms_segment(cbs->value);
  89.     if (strlen(FileName) == 0) {
  90.       sprintf(msgstring, "Invalid Book File Name");
  91.       DialogType = 1;
  92.       popup_Message();
  93.     }
  94.     else if (FileMode == 2) {                /* Write File */
  95.       if (access(FileName, F_OK) != 0) {
  96.         RDwin = -1;
  97.         UxPopdownInterface(BookFile);
  98.         InterfaceWinOpen-- ;
  99.             if (ASCII)
  100.            write_ascii(FileName);
  101.             else
  102.            write_file(FileName);
  103.       }
  104.       else {
  105.         DialogType = 4;
  106.         popup_Question();
  107.         UxWaitForNotify();
  108.       }
  109.     }
  110.     else if (FileMode == 1) {                /* Read File */
  111.       if (access(FileName, F_OK) != 0) {
  112.         sprintf(msgstring, "Invalid Book File Name");
  113.         DialogType = 1;
  114.         popup_Message();
  115.       }
  116.       else {
  117.         RDwin = -1;
  118.         UxPopdownInterface(BookFile);
  119.         InterfaceWinOpen-- ;
  120.         read_file(FileName);
  121.         drawscene(0);
  122.         if (message_waiting) {
  123.             popup_Message();
  124.             message_waiting = FALSE;
  125.         }
  126.       }
  127.     }
  128.     }
  129.     UxBookFileContext = UxSaveCtx;
  130. }
  131.  
  132. static void    cancelCB_BookFile( UxWidget, UxClientData, UxCallbackArg )
  133.     Widget        UxWidget;
  134.     XtPointer    UxClientData, UxCallbackArg;
  135. {
  136.     _UxCBookFile            *UxSaveCtx, *UxContext;
  137.  
  138.     UxSaveCtx = UxBookFileContext;
  139.     UxBookFileContext = UxContext =
  140.             (_UxCBookFile *) UxGetContext( UxWidget );
  141.     {
  142.     RDwin = -1;
  143.     UxPopdownInterface(BookFile);
  144.     InterfaceWinOpen-- ;
  145.     }
  146.     UxBookFileContext = UxSaveCtx;
  147. }
  148.  
  149. /*******************************************************************************
  150.         The 'build_' function creates all the Widgets and X widgets,
  151.         and sets their properties to the values specified in the
  152.         Property Editor.
  153. *******************************************************************************/
  154.  
  155. Widget BookFile_shell;
  156.  
  157. static Widget    _Uxbuild_BookFile()
  158. {
  159.  
  160.     BookFile_shell = XtVaCreatePopupShell( "BookFile_shell",
  161.             xmDialogShellWidgetClass, DBtoplevel,
  162.             XmNx, 725,
  163.             XmNy, 237,
  164.             XmNwidth, 340,
  165.             XmNheight, 420,
  166.             XmNtitle, "BookFile",
  167.             NULL );
  168.  
  169.     BookFile = XtVaCreateWidget( "BookFile",
  170.             xmFileSelectionBoxWidgetClass, BookFile_shell,
  171.             XmNtextColumns, 32,
  172.             XmNminimizeButtons, FALSE,
  173.             XmNlistVisibleItemCount, 8,
  174.             XmNdialogType, XmDIALOG_FILE_SELECTION,
  175.             RES_CONVERT( XmNtextFontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
  176.             XmNresizePolicy, XmRESIZE_ANY,
  177.             XmNnoResize, FALSE,
  178.             XmNmarginWidth, 10,
  179.             XmNmarginHeight, 10,
  180.             RES_CONVERT( XmNlabelFontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  181.             RES_CONVERT( XmNdialogTitle, "BookFile" ),
  182.             XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  183.             RES_CONVERT( XmNbuttonFontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  184. /*
  185.             XmNshadowThickness, 5,
  186.             RES_CONVERT( XmNforeground, "black" ),
  187.             RES_CONVERT( XmNbottomShadowColor, "#6c6c6c" ),
  188.             RES_CONVERT( XmNtopShadowColor, "#e5e5e5" ),
  189.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  190. */
  191.             XmNheight, 420,
  192.             XmNwidth, 340,
  193.             NULL );
  194.  
  195.     UxPutContext( BookFile, (char *) UxBookFileContext );
  196.  
  197.     XtAddCallback( BookFile, XmNdestroyCallback,
  198.             UxFreeClientDataCB,
  199.             (XtPointer) UxBookFileContext );
  200.  
  201.     XtAddCallback( BookFile, XmNokCallback,
  202.             okCallback_BookFile,
  203.             (XtPointer) UxBookFileContext );
  204.     XtAddCallback( BookFile, XmNcancelCallback,
  205.             cancelCB_BookFile,
  206.             (XtPointer) UxBookFileContext );
  207.  
  208.  
  209.     return ( BookFile );
  210. }
  211.  
  212. /*******************************************************************************
  213.     The following function includes the code that was entered
  214.     in the 'Initial Code' and 'Final Code' sections of the
  215.     Declarations Editor. This function is called from the
  216.     'Interface function' below.
  217. *******************************************************************************/
  218.  
  219. static Widget    _Ux_create_BookFile()
  220. {
  221.     Widget                 rtrn;
  222.     _UxCBookFile            *UxContext;
  223.     char dir_mask[128];
  224.     char dir_spec[128];
  225.     char *cwd;
  226.     char buf[128];
  227.  
  228.     UxBookFileContext = UxContext =
  229.         (_UxCBookFile *) XtMalloc( sizeof(_UxCBookFile) );
  230.  
  231.     rtrn = _Uxbuild_BookFile();
  232.  
  233.     if ((cwd = getcwd(buf, 128)) == NULL) {
  234.       printf("Error in getcwd.  Setting a default directory.\n");
  235.       strcpy(dir_spec, ".");
  236.     }
  237.     else
  238.       strcpy(dir_spec, cwd);
  239.     strcat (dir_spec, "/");
  240.     strcpy (dir_mask, dir_spec);
  241.     strcat (dir_mask, "*.out");
  242.     XtVaSetValues( BookFile,
  243.             RES_CONVERT( XmNdirMask, dir_mask ), NULL );
  244.     XtVaSetValues( BookFile, 
  245.             RES_CONVERT( XmNdirSpec, dir_spec ), NULL );
  246.  
  247. /*
  248.     XtVaSetValues( XmFileSelectionBoxGetChild(BookFile, XmDIALOG_TEXT),
  249.             RES_CONVERT( XmNbackground, "#7777BB" ), NULL );
  250.     XtVaSetValues( XmFileSelectionBoxGetChild(BookFile, XmDIALOG_FILTER_TEXT),
  251.             RES_CONVERT( XmNbackground, "#7777BB" ), NULL );
  252.     XtVaSetValues( XmFileSelectionBoxGetChild(BookFile, XmDIALOG_DIR_LIST),
  253.             RES_CONVERT( XmNbackground, "#7777BB" ), NULL );
  254.     XtVaSetValues( XmFileSelectionBoxGetChild(BookFile, XmDIALOG_FILE_LIST),
  255.             RES_CONVERT( XmNbackground, "#7777BB" ), NULL );
  256. */
  257.  
  258.     XtRealizeWidget( BookFile_shell );
  259.  
  260.     XtUnmanageChild(XmFileSelectionBoxGetChild(
  261.       (BookFile), XmDIALOG_HELP_BUTTON));
  262.  
  263.     SetWMhints ( BookFile_shell );
  264.  
  265.     return(rtrn);
  266. }
  267.  
  268. /*******************************************************************************
  269.     The following is the 'Interface function' which is the
  270.     external entry point for creating this interface.
  271.     This function should be called from your application or from
  272.     a callback function.
  273. *******************************************************************************/
  274.  
  275. Widget    create_BookFile()
  276. {
  277.     Widget            _Uxrtrn;
  278.  
  279.     _Uxrtrn = _Ux_create_BookFile();
  280.  
  281.     return ( _Uxrtrn );
  282. }
  283.  
  284. /*******************************************************************************
  285.     END OF FILE
  286. *******************************************************************************/
  287.  
  288.